<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'edit_sys_user_info.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="${ctx }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${ctx }/css/font-awesome.css?v=4.4.0" rel="stylesheet">

<!-- jqgrid-->
<link href="${ctx }/css/plugins/jqgrid/ui.jqgrid.css?0820"
	rel="stylesheet">

<link href="${ctx }/css/animate.css" rel="stylesheet">
<link href="${ctx }/css/style.css?v=4.1.0" rel="stylesheet">
<style type="text/css">
body {
	background: none;
}
</style>
</head>

<div class="inmodal"  role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content animated bounceInRight">
			<div class="modal-header">
				<button type="button" class="close closeWin" data-dismiss="modal">
					<span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
				</button>
				<h4 class="modal-title">修改用户</h4>
			</div>
			<div class="ibox-content">

				<form id="editSysUserInfoForm" class="form-horizontal m-t">
					<input id="reserved1" name="reserved1" type="hidden"
						value="${sysUserInfo.reserved1 }">
					
					<div class="form-group">
						<label class="col-sm-3 control-label">用户编号：</label>
						<div class="col-sm-5">
							<input id="emp_id" name="emp_id" class="form-control"
								type="text" 
								value="${sysUserInfo.emp_id }" readonly="readonly">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">用户名称：</label>
						<div class="col-sm-5">
							<input id="emp_name" name="emp_name" class="form-control"
								type="text" aria-required="true" required=""
								value="${sysUserInfo.emp_name }" placeholder="请输入用户姓名">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">用户电话：</label>
						<div class="col-sm-5">
							<input id="mobile_phone" name="mobile_phone" class="form-control"
								required="" aria-required="true" type="text"
								value="${sysUserInfo.mobile_phone }" placeholder="请输入手机号码">
						</div>
					</div>
  					<div class="form-group">
                        	<label class="col-sm-3 control-label">座机：</label>
                            <div class="col-sm-8">
                            	<input id="telephone" name="telephone" class="form-control"  aria-required="true" type="text" placeholder="请输入座机" value="${sysUserInfo.telephone}">                                    
                            </div>
                    </div>
					<div class="form-group">
						<label class="col-sm-3 control-label">邮件：</label>
						<div class="col-sm-5">
							<input id="email" name="email" class="form-control"
								aria-required="true" type="text" value="${sysUserInfo.email }" placeholder="请输入邮件地址">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">用户性别：</label>
						<div class="col-sm-5">
							<input type="radio" id="sex" name="sex" value="1"
								<c:if test="${sysUserInfo.sex==1}">checked</c:if>>男 <input
								type="radio" id="sex" name="sex" value="0"
								<c:if test="${sysUserInfo.sex==0}">checked</c:if>>女

						</div>
					</div>
					 <div class="form-group">
						<label class="col-sm-3 control-label">职务：</label>
						<div class="col-sm-5">
							<input id="position" name="position" class="form-control"
								 aria-required="true" type="text"
								value="${sysUserInfo.position }" placeholder="请输入职务名称">
						</div>
					</div>
				<div class="form-group">
						<label class="col-sm-3 control-label">专业：</label>
						<div class="col-sm-5">
							<input id="professional" name="professional" class="form-control"
								aria-required="true" type="text"
								value="${sysUserInfo.professional }" placeholder="请输入专业名称">
						</div>
					</div>
					<%-- <div class="form-group">
                        	<label class="col-sm-3 control-label">是否上级：</label>
                            <div class="col-sm-8">
                            	<input id="isleader" name="isleader"  type="radio" value="0" <c:if test="${!sysUserInfo.isleader}">checked="checked"</c:if>>普通成员  
                            	<input id="isleader" name="isleader"  type="radio" value="1" <c:if test="${sysUserInfo.isleader}">checked="checked"</c:if>>上级                                
                            </div>
                        </div> --%>
					 <div class="form-group">
						<label class="col-sm-3 control-label">排序：</label>
						<div class="col-sm-8">
							<input id="emp_order" name="emp_order" class="form-control"
								required="" aria-required="true" type="number"
								placeholder="请输入排序号" value="${sysUserInfo.emp_order}">
						</div>
					</div> 
					<div class="form-group">
						<div class="col-sm-5 col-sm-offset-3">
							<button type="button" class="btn btn-white closeWin"
								id="closeWin">关闭</button>
							<button type="submit" class="btn btn-primary">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 全局js -->
<script src="${ctx }/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx }/js/bootstrap.min.js?v=3.3.6"></script>

<!-- Peity -->
<script src="${ctx }/js/plugins/peity/jquery.peity.min.js"></script>

<!-- jqGrid -->
<script src="${ctx }/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="${ctx }/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

<!-- jQuery Validation plugin javascript-->
<script src="${ctx }/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctx }/js/plugins/validate/messages_zh.min.js"></script>

<!-- layer javascript -->
<script src="${ctx }/js/plugins/layer/layer.min.js"></script>

<!-- jQuery form-->
<script src="${ctx }/js/jquery.form.js"></script>

<!-- 自定义js ---->
<script src="${ctx }/js/content.js?v=1.0.0"></script>
<script src="${ctx }/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
	var val=$("#editSysUserInfoForm").find("input:radio[name='level']:checked").val();
	changeLevel(val);
	$('#pass').blur(function() {
			var reg = /^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*).{8,20}$/;
			var v_password = $('#pass').val();
			$('#pass').next().remove();
			if (v_password.match(reg) == null) {
				var spa = '<span class="help-block m-b-none" style="color: red;">密码必须包含英文大写、小写和数字，长度为8-20位</span>';
				$('#pass').after(spa);
				return false;
			}
			if (v_password.length < 8) {
				var spa = '<span class="help-block m-b-none" style="color: red;">密码不能小于8位</span>';
				$('#pass').after(spa);
				return false;
			}
			/* var v_userName = $('#account')
					.val();
			if (v_userName == v_password) {
				var spa = '<span class="help-block m-b-none" style="color: red;">账户和密码不能一致</span>';
				$('#password').after(spa);
				return false;
			} */
		});
		
		$('#password').blur(function(){
			var pass1=$('#pass').val();
			var pass2=$('#password').val();
			if(!pass2){
				return ;
			}
			$('#password').next().remove();
			if(pass1!=pass2){
				var spa = '<span class="help-block m-b-none" style="color: red;">两次密码不一致</span>';
				$('#password').after(spa);
				return false;
			}
			
		});
    	
    	//changeLevel('1');//默认不是揽件员
    	function changeLevel(value){
    		//console.log();
    		if(value=='0'){
    			$("#account").parent().parent().show();
    			$("#account").attr("required","");
    			
    			$("#pass").parent().parent().show();
    			$("#pass").attr("required","");
    			$("#password").parent().parent().show();
    			$("#password").attr("required","");
    			$("#telephone").parent().parent().hide();
    			$("#email").parent().parent().hide();
    			$("#position").parent().parent().hide();
    			$("#isleader").parent().parent().hide();
    		}else{
    			$("#account").parent().parent().hide();
    			$("#account").removeAttr("required");
    			$("#pass").parent().parent().hide();
    			$("#pass").removeAttr("required");
    			$("#password").parent().parent().hide();
    			$("#password").removeAttr("required");
    			$("#telephone").parent().parent().show();
    			$("#email").parent().parent().show();
    			$("#position").parent().parent().show();
    			$("#isleader").parent().parent().show();
    		}
    	}
	$(document).ready(function() {

		$.jgrid.defaults.styleUI = 'Bootstrap';

		//绑定修改表单提交事件,异步提交表单
		$('#editSysUserInfoForm').submit(function() {
			var val=$("#editSysUserInfoForm").find("input:radio[name='level']:checked").val();
        	
        	if(val=='1'){
    			$("#account").val('');
    			$("#pass").val('');
    			$("#password").val('');
    		}
    		
    		 var pass1=$('#pass').val();
			var pass2=$('#password').val();
			$('#password').next().remove();
			if(pass1!=pass2){
				var spa = '<span class="help-block m-b-none" style="color: red;">两次密码不一致</span>';
				$('#password').after(spa);
				return false;
			} 
			var text=$('#account').next().text();
			if(text){
				return false;
			}
			$.ajax({
				type : "post",
				url : "${ctx }/organize/doEditSysUser",
				data : $('#editSysUserInfoForm').serialize(),
				success : function(data) {
					if (data.result == '0') {
						layer.alert(data.msg, {
							icon : 1
						}, function(index) {
							//刷新表格数据
							window.parent.editWinClose('0');
							//关闭提示框
							layer.close(index);
						});
					} else {
						layer.alert(data.msg, {
							icon : 2
						});
					}
					;
				},
				error : function() {
					layer.alert('修改用户异常！', {
						icon : 2
					});
				}
			});
			return false;
		});

		$('.closeWin').click(function() {
			window.parent.editWinClose('1');
		});

	});
	
	 $("#account").blur(function(){
       	var oldacc='${sysUserInfo.account }';//获取原账号
       	 var account=$("#account").val();
       	 if(account==''){
       	 	return;
       	 }
       	 if(oldacc==account){//如果新账号与原账号相同则不校验
       	 	$('#account').next().remove();
       	 	return;
       	 }
       	 $.ajax({
				type: "post",
				dataType:"json",
				url: "${ctx }/organize/getSysUserByAccount",
				data:  "account="+account,
				success: function(data) {
					$('#account').next().remove();
					if(data.status=='0'){//未被注册
						
					}else{//已被注册
						var spa = '<span class="help-block m-b-none" style="color: red;">该账号已被使用！</span>';
						$('#account').after(spa);
					}
				}
		 });
      });
</script>
</html>
